/**
 * Thread
 *
 * Test and example for creating threads
 *
 * @author Jasper Nevens <jasper@nevensit.be>
 * @date    19/02/11
 */

#include "thread.h"
#include <pthread.h>
#include <iostream>

using namespace std;

class MyThread : public Thread {
	public:
		void execute();
		int i;
};

void MyThread::execute() {
	sleep(i);
	cout << "Execute:" << i << endl;
}

int main(int argc, char *argv[])
{
	const int THREAD_COUNT = 3;

	// create threads
	MyThread t[THREAD_COUNT];
	for (int i=THREAD_COUNT-1; i>=0; i--) { // start the threads in the opposite order to prove multi-threading
		cout << "Start:" << i << endl;
		t[i].i = i;
		t[i].start();
	}

	// wait until all threads have finished
	for (int i=0; i<THREAD_COUNT;i++) {
		t[i].wait_for_exit();
	}
	return 0;
}

